package h2UDP;

import java.io.IOException;
import java.net.*;
import java.nio.charset.StandardCharsets;

public class SendDemo {
    public static void main(String[] args) throws IOException {

        //创建发送端socket对象

        //DatagramSocket 构造数据报
        DatagramSocket ds=new DatagramSocket();

        //创建数据

        //调用DatagramSocket对象的方法发送数据

        byte [] bys="hello，udp,我来了".getBytes();
//        InetAddress address = InetAddress.getByName("127.0.0.1");
//        int length=bys.length;
//        int port =10086;
        DatagramPacket dp=new DatagramPacket(bys,bys.length,InetAddress.getByName("127.0.0.1"),10086);
        ds.send(dp);


        //关闭发送端
        ds.close();
    }
}
